/**
 * Created by Administrator on 2018/10/19.
 */
$(function () {
	
	//轮播图
	
	var bannerTimer = null;
	var bannerI = 0;
	
  $(".banner_box .imgBox img").eq(0).fadeIn(300);
  $(".banner_box .yuan li").eq(0).attr("class","active");

  $(".banner_box .yuan li").mouseover(function(){
  	$(".banner_box .imgBox img").eq($(this).index()).fadeIn().siblings().fadeOut();
  	$(".banner_box .yuan li").eq($(this).index()).attr('class','active').siblings().attr('class','');
  	
  })
  
  $(".banner_box").mousemove(function(){
  	clearTimeout(bannerTimer)
  })

  $(".banner_box .yuan").mousemove(function(){
    clearTimeout(bannerTimer)
  })

  $(".banner_box").mouseout(function(){
  	setBanner()
  })
  
  $(".banner_box .yuan").mouseout(function(){
    setBanner()
  })
  
  setBanner()
  
  
  //产品轮播
	var hotSellingGoods_cen = $(".hotSellingGoods_box .hotSellingGoods_cen");

  	var infin_box_len = hotSellingGoods_cen.size()

	var left_arr = new Array();
    var infinWidth_arr = new Array();

	for(var i=0;i<infin_box_len;i++){
        var infinWidth = hotSellingGoods_cen.eq(i).find('li').size() * 209;
        if(infinWidth <= 1045){
            hotSellingGoods_cen.eq(i).find('.rigbtn').hide()
            hotSellingGoods_cen.eq(i).find('.letbtn').hide()
        }else if(infinWidth >= 1045){
            hotSellingGoods_cen.eq(i).find('.letbtn').hide()
        }
        hotSellingGoods_cen.eq(i).find('.infin_box').css("width",infinWidth);

        left_arr[i] = 0;
        infinWidth_arr[i] = infinWidth;

	}

  //产品轮播图右边
  $(".hotSellingGoods_box .hotSellingGoods_cen .rigbtn img").click(function(){
      var hotSellingGoods_cen = $(this).parents('.hotSellingGoods_cen');
      var index = hotSellingGoods_cen.index();

      var ileft = hotSellingGoods_cen.find('.infin_box').scrollLeft() + left_arr[index];

  	if(ileft >= infinWidth_arr[index]/2){
        hotSellingGoods_cen.find('.rigbtn').hide()
  		return false;
  	}else{
        left_arr[index]+=209;
        ileft = hotSellingGoods_cen.find('.infin_box').scrollLeft() + left_arr[index];

        hotSellingGoods_cen.find('.letbtn').show()
        hotSellingGoods_cen.find('.infin_box').stop().animate({
            'left':-ileft
        })

  		if(ileft >= infinWidth_arr[index]/2){
            hotSellingGoods_cen.find('.rigbtn').hide()
              return false;
	  	}
  	}
  	
  })
 
  //产品轮播图左边
  $(".hotSellingGoods_box .hotSellingGoods_cen .letbtn img").click(function(){
      var hotSellingGoods_cen = $(this).parents('.hotSellingGoods_cen');
      var index = hotSellingGoods_cen.index();

      var ileft = hotSellingGoods_cen.find('.infin_box').scrollLeft() + left_arr[index];

  	if(ileft <= 0){
        hotSellingGoods_cen.find('.letbtn').hide()
  		return false;
  	}else{
        left_arr[index]-=209;
        ileft = hotSellingGoods_cen.find('.infin_box').scrollLeft() + left_arr[index];
        hotSellingGoods_cen.find('.rigbtn').show()
        hotSellingGoods_cen.find('.infin_box').stop().animate({
            'left':-ileft
        })
  		
  		if(ileft <= 0){
            hotSellingGoods_cen.find('.letbtn').hide()
	  		return false;
	  	}
  	}
  	
  })
  
  
  function setBanner(){
    clearTimeout(bannerTimer)
  	bannerTimer = setInterval(function(){
	  	bannerI++
	  	
	  	if(bannerI >= $(".banner_box .yuan li").size()){
	  		bannerI = 0
	  	}
	 
	  	$(".banner_box .imgBox img").eq(bannerI).fadeIn().siblings().fadeOut();
	  	$(".banner_box .yuan li").eq(bannerI).attr('class','active').siblings().attr('class','');
	  	
	  },3000)
  }
  
  $(".timeLimit_box .timeLimit_cen .top .list_box .list").click(function(){
  	$(".timeLimit_box .timeLimit_cen .cp_box").hide();
  	$(".timeLimit_box .timeLimit_cen .cp_box").eq($(this).index()).show();
  	$(".timeLimit_box .timeLimit_cen .top .list_box .list").eq($(this).index()).attr("class","list active").siblings().attr("class","list")
  })
})